define(
    ["PDUtilDir/dataService", "PDUtilDir/grid", "PDUtilDir/searchBlock", "PDUtilDir/util", "PDUtilDir/tool", "PDUtilDir/slidebar", "PDUtilDir/inputSelect", "Date", "DateCN", "css!DateCss"],
    function (DataService, Grid, SearchBlock, Util, Tool, Slidebar, inputSelect) {
        function addCarSupportInit($scope, $compile) {
            return new addCarSupport($scope, $compile);
        };

        function addCarSupport($scope, $compile) {
            this.$scope = $scope;
            this.$compile = $compile;
        };
        addCarSupport.fn = addCarSupport.prototype;

        addCarSupport.fn.init = function () {
            var _this = this;
            _this.entity = {
                cars: new Array()
            };
            _this.search = {};
        };

        addCarSupport.fn.digest = function () {
            this.$scope.$digest();
        };

        addCarSupport.fn.run = function () {
            var _this = this;
            _this.init();

            this.slidebars = Slidebar({
                size: 'lg',
                url: getServer()
                + "/static/app/fleet/cteamOrderInfos/views/car.html",
                $scope: _this.$scope,
                $compile: _this.$compile,
                afterLoad: function ($Panel) {
                    _this.initialization();
                }
            });
        };
        addCarSupport.fn.initialization = function () {
            this.baseInit();
        };
        /* 查询 start */
        addCarSupport.fn.searchSupport = function () {
            var _this = this;
            return {
                run: function(){
                    console.info(_this);
                    _this.grid.reload({
                        queryParam : {
                            model: JSON.stringify(_this.search)
                        }
                    })
                }
            }
        };
        addCarSupport.fn.save = function() {
            DataService.setObject('car.team.search.cars', this.entity.cars);
            this.$scope.agreeSupport.reloadCarsSupport().run();
            this.slidebars.close();
        };
        addCarSupport.fn.baseInit = function () {
            var _this = this;

            // SearchBlock.init('CarSearchBlockId');
            _this.grid = Grid({
                id: "CarGirdDivId",
                pageSize: 10,
                index: true,
                multi: true,
                pagination: true,
                cache: false,
                onSeletedChanged : function(data) {
                    _this.entity.cars = data;
                    _this.digest();
                },
                layout: [ {
                    name : "车牌号",
                    field : "plateNumber",
                    sort : true
                }, {
                    name : "代码",
                    field : "code",
                    sort : true
                }, {
                    name : "车辆类型",
                    field : "type",
                    format:function(e){
                        // if(!cache.types)
                        //     return;
                        // for(var i=0;i<cache.types.length;i++){
                        //     if(cache.types[i].dictCode==e.row.type){
                        //         return cache.types[i].dictName;
                        //     }
                        // }
                    }
                }, {
                    name : "座位数",
                    field : "seatNumber"
                }, {
                    name : "品牌型号",
                    field : "brandModel"
                }, {
                    name : "识别代码",
                    field : "identificationCode"
                }, {
                    name : "发动机号码",
                    field : "engineNumber"
                }],
                toolbar: [/* {
                    name : "查询",
                    icon : "fa fa-search",
                    callback : function(event) {
                        _this.searchSupport().run();
                    }
                }*/],
                data : {
                    type : 'URL',
                    // value : getServer() + '/flea/hclv/car/selectByDeptId.htmls'
                    value : getServer() + '/flea/hclv/car/reserve/getRequireCars.htmls?reserveCarId=' + _this.$scope.agreeSupport.entity.id
                }
            });
        };

        return addCarSupportInit;
    });